using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace Minesweeper02
{
	/// <summary>
	/// Summary description for Custom.
	/// </summary>
	public class Custom : System.Windows.Forms.Form
	{
		private int columns;
		private int rows;
		private int totalmines;
		private bool mark;
		private System.Windows.Forms.TextBox Columns;
		private System.Windows.Forms.TextBox Rows;
		private System.Windows.Forms.TextBox TotalMine;
		private System.Windows.Forms.Button Register;
		private System.Windows.Forms.Button Cancel;
		private System.Windows.Forms.Label height;
		private System.Windows.Forms.Label width;
		private System.Windows.Forms.Label mines;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Custom(int _columns,int _rows,int _totalMine,bool _mark)
		{
			//
			// Required for Windows Form Designer support
			//
			columns=_columns;
			rows=_rows;
			totalmines=_totalMine;
			mark=_mark;
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.height = new System.Windows.Forms.Label();
			this.width = new System.Windows.Forms.Label();
			this.mines = new System.Windows.Forms.Label();
			this.Columns = new System.Windows.Forms.TextBox();
			this.Rows = new System.Windows.Forms.TextBox();
			this.TotalMine = new System.Windows.Forms.TextBox();
			this.Register = new System.Windows.Forms.Button();
			this.Cancel = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// height
			// 
			this.height.Location = new System.Drawing.Point(8, 32);
			this.height.Name = "height";
			this.height.Size = new System.Drawing.Size(72, 40);
			this.height.TabIndex = 0;
			this.height.Text = "Height";
			this.height.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// width
			// 
			this.width.Location = new System.Drawing.Point(8, 72);
			this.width.Name = "width";
			this.width.Size = new System.Drawing.Size(72, 40);
			this.width.TabIndex = 1;
			this.width.Text = "Width";
			this.width.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// mines
			// 
			this.mines.Location = new System.Drawing.Point(8, 112);
			this.mines.Name = "mines";
			this.mines.Size = new System.Drawing.Size(72, 40);
			this.mines.TabIndex = 8;
			this.mines.Text = "Mines";
			this.mines.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// Columns
			// 
			this.Columns.Location = new System.Drawing.Point(104, 40);
			this.Columns.Name = "Columns";
			this.Columns.Size = new System.Drawing.Size(40, 20);
			this.Columns.TabIndex = 3;
			this.Columns.Text = columns.ToString();
			// 
			// Rows
			// 
			this.Rows.Location = new System.Drawing.Point(104, 80);
			this.Rows.Name = "Rows";
			this.Rows.Size = new System.Drawing.Size(40, 20);
			this.Rows.TabIndex = 4;
			this.Rows.Text = rows.ToString();
			// 
			// TotalMine
			// 
			this.TotalMine.Location = new System.Drawing.Point(104, 120);
			this.TotalMine.Name = "TotalMine";
			this.TotalMine.Size = new System.Drawing.Size(40, 20);
			this.TotalMine.TabIndex = 5;
			this.TotalMine.Text = totalmines.ToString();
			// 
			// Register
			// 
			this.Register.Location = new System.Drawing.Point(168, 48);
			this.Register.Name = "Register";
			this.Register.Size = new System.Drawing.Size(64, 32);
			this.Register.TabIndex = 6;
			this.Register.Text = "Ok";
			this.Register.Click += new System.EventHandler(this.Register_Click);
			// 
			// Cancel
			// 
			this.Cancel.Location = new System.Drawing.Point(168, 96);
			this.Cancel.Name = "Cancel";
			this.Cancel.Size = new System.Drawing.Size(64, 32);
			this.Cancel.TabIndex = 7;
			this.Cancel.Text = "Cancel";
			this.Cancel.Click += new System.EventHandler(this.Cancel_Click);
			// 
			// Custom
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(248, 182);
			this.Controls.Add(this.Cancel);
			this.Controls.Add(this.Register);
			this.Controls.Add(this.TotalMine);
			this.Controls.Add(this.Rows);
			this.Controls.Add(this.Columns);
			this.Controls.Add(this.mines);
			this.Controls.Add(this.width);
			this.Controls.Add(this.height);
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "Custom";
			this.Text = "Custom Feild";
			this.ResumeLayout(false);

		}
		#endregion

		private void Register_Click(object sender, System.EventArgs e)
		{
            MineResourceSet rs=new MineResourceSet("Play.resources");
			int _columns,_rows,_totalmines;
			if(IsInt(this.Columns.Text) && IsInt(this.Rows.Text) && IsInt(this.TotalMine.Text))
			{
				_columns=int.Parse(this.Columns.Text);
				_rows=int.Parse(this.Rows.Text);
				_totalmines=int.Parse(this.TotalMine.Text);
				if (_columns==0 || _rows==0 || _totalmines==0 || (_totalmines>(_columns*_rows/2)) ) 	
				{
                   
				}
				else{
					columns=_columns;
					rows=_rows;
					totalmines=_totalmines;
				}
			}
			else{
			//	rs.SaveAttribute("Custom",columns,rows,totalmines,mark);
			}
			rs.SaveAttribute("Custom",columns,rows,totalmines,mark);
			rs.SetIsContinue(true);
			this.Close();
		}
		private bool IsInt(string str){
		    bool testvar=true;
			string strtest="0123456789";
			for (int i=0;i<str.Length;i++){
				if (strtest.IndexOf(str[i],0,10)<0){
					testvar=false;;
				}
			}
			return testvar;
		}
		private void Cancel_Click(object sender, System.EventArgs e)
		{
			MineResourceSet rs=new MineResourceSet("Play.resources");
			rs.SaveAttribute("Custom",columns,rows,totalmines,mark);
			rs.SetIsContinue(true);
			this.Close();
		   
		}
	}
}
